const throttle = (fn: any, delay = 300) => {
  let timer: NodeJS.Timeout | null = null
  return function (...args: any) {
    if (!timer) {
      timer = setTimeout(() => {
        fn.call(this, ...args)
        timer = null
      }, delay)
    }
  }
}
export { throttle }

const debounce = (fn: any, delay = 300) => {
  let timer: string | number | NodeJS.Timeout | null | undefined = null
  return function (...args: any) {
    if (timer) {
      clearTimeout(timer)
    }
    timer = setTimeout(() => {
      fn.call(this, ...args)
      timer = null
    }, delay)
  }
}
export { debounce }
